package com.dreamtour.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dreamtour.entity.Feedbacks;
import com.dreamtour.entity.Services;
import com.dreamtour.mapper.AdministratorsMapper;
import com.dreamtour.mapper.FeedbacksMapper;
import com.dreamtour.service.IFeedbacksService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xls
 * @since 2024-12-24
 */
@Service
public class FeedbacksServiceImpl extends ServiceImpl<FeedbacksMapper, Feedbacks> implements IFeedbacksService {
    @Autowired
    private FeedbacksMapper feedbacksMapper;

    @Override
    public List<Feedbacks> getReports() {
        return feedbacksMapper.findReports();
    }

    @Override
    public List<Feedbacks> getSuggestions() {
        return feedbacksMapper.findSuggestions();
    }

    @Override
    public List<Map<String, Object>> countFeedbacksByMonth() {
        QueryWrapper<Feedbacks> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("count(*) as count, DATE_FORMAT(reportedAt, '%m') as month");
        queryWrapper.groupBy("month");
        queryWrapper.orderByDesc("month");
        return feedbacksMapper.selectMaps(queryWrapper);
    }

    @Override
    public Feedbacks findById(Integer feedbackId) {
        return feedbacksMapper.selectById(feedbackId);
    }
}